<template>
    <div>
        <h3>修改页面</h3>

        <thead>
            <table>
                <tr>
                    <td>
                        名称
                        <input type="text" v-model="data.Ename">
                    </td>
                </tr>
                <tr>
                    <td>
                        性别
                        <input type="radio" name="sex" :value="1" checked>男
                        <input type="radio" name="sex" :value="2" >女
                    </td>
                </tr>
                <tr>
                    <td>
                        地址
                        <input type="text" v-model="data.Eaddr">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="button" value="修改" @click="Upd(data.Eid)">
                        <a href="/">返回列表</a>
                    </td>
                </tr>
            </table>
        </thead>
    </div>
</template>

<script setup lang="ts">

import {ref,onMounted} from "vue"
import axios from "axios";
import {useRoute} from "vue-router"
import {useRouter} from "vue-router"

const route=useRoute();
const router=useRouter();


const data=ref({
        "Eid": 0,
        "Ename": "",
        "Esex": 0,
        "Ebirthday": "",
        "Eaddr": ""
  })

const getdata=()=>{
    var vid=route.query.id;
    axios.get("https://localhost:7013/api/Emp/Fan",{params:{id:vid}}).then(res=>{
        data.value=res.data;
    })
}

onMounted(()=>{
    getdata()
})


const Upd=(val:any)=>{
    axios.post("https://localhost:7013/api/Emp/Update",data.value).then(res=>{
    if(res.data>0)
    {
        alert("修改成功");
        router.push({name:'list'})
    }
    else
    {
        alert("修改失败");
    }
})
}

</script>

<style scoped>

</style>